package com.lovi.view;

import com.lovi.domain.DiningTable;
import com.lovi.domain.Employee;
import com.lovi.domain.Menu;
import com.lovi.domain.MultiTableBean;
import com.lovi.service.BillService;
import com.lovi.service.DiningTableService;
import com.lovi.service.EmployeeService;
import com.lovi.service.MenuService;
import com.lovi.utils.ScannerUtils;
import org.junit.jupiter.api.Test;

import java.util.List;

public class MHLView {

    //控制是否退出菜单
    private boolean loop = true;
    private String key = ""; //接收用户的选择
    //定义EmployeeService 属性
    private EmployeeService employeeService = new EmployeeService();
    //餐桌相关
    private DiningTableService diningTableService = new DiningTableService();
    //菜单相关
    private MenuService menuService = new MenuService();
    //账单相关
    private BillService billService = new BillService();


    public static void main(String[] args) {
        new MHLView().mainMenu();
    }

    //完成结账
    public void payBill(String empId) {
        System.out.println("=========结账服务=====================================");
        boolean b = billService.payBill(empId);
        if(b) {
            System.out.println("=========结账成功==========");
        }else {
            System.out.println("=========结账失败==========");
        }

    }

    //显示账单信息
    public void listCurrentUserBill(String empId) {
        billService.listCurrentUserBill(empId);
    }


    //完成点餐
    public void orderMenu(String empId) {
        menuService.orderMenu(empId);

    }

    //显示所有菜品
    public void listMenu() {
        List<Menu> list = menuService.list();
        System.out.println("菜品编号\t\t菜品名称\t\t菜品类别\t\t菜品价格");
        list.forEach(System.out::println);
    }

    //完成订座
    public void orderDiningTable(String empId) {
        boolean b = diningTableService.orderDiningTable(empId);
        if (b){
            System.out.println("=========预定成功==========");
        }else {
            System.out.println("=========预定失败==========");
        }

    }

    //显示所有餐桌状态
    public void listDiningTable() {
        List<DiningTable> list = diningTableService.list();
        System.out.println("餐桌编号\t\t状态");
        list.forEach(System.out::println);
        System.out.println("=========显示完毕==========");

    }

    //显示主菜单
    public void mainMenu() {

        while (loop) {

            System.out.println("\n===============满汉楼================");
            System.out.println("\t\t 1 登录满汉楼");
            System.out.println("\t\t 2 退出满汉楼");
            System.out.print("请输入你的选择: ");
            key = ScannerUtils.readString(1);
            switch (key) {
                case "1":
                    System.out.print("输入员工号: ");
                    String empId = ScannerUtils.readString(50);
                    System.out.print("输入密  码: ");
                    String pwd = ScannerUtils.readString(50);
                    Employee employee = employeeService.getEmployeeByIdAndPwd(empId, pwd);
                    if (employee != null) { //说明存在该用户
                        System.out.println("===============登录成功[" + employee.getName() + "]================\n");
                        //显示二级菜单, 这里二级菜单是循环操作，所以做成while
                        while (loop) {
                            System.out.println("\n===============满汉楼(二级菜单)================");
                            System.out.println("\t\t 1 显示餐桌状态");
                            System.out.println("\t\t 2 预定餐桌");
                            System.out.println("\t\t 3 显示所有菜品");
                            System.out.println("\t\t 4 点餐服务");
                            System.out.println("\t\t 5 查看账单");
                            System.out.println("\t\t 6 结账");
                            System.out.println("\t\t 9 退出满汉楼");
                            System.out.print("请输入你的选择: ");
                            key = ScannerUtils.readString(1);
                            switch (key) {
                                case "1":
                                    listDiningTable();//显示餐桌状态
                                    break;
                                case "2":
                                    orderDiningTable(empId);
                                    break;
                                case "3":
                                    listMenu();
                                    break;
                                case "4":
                                    orderMenu(empId);
                                    break;
                                case "5":
                                    listCurrentUserBill(empId);//显示该用户的账单
                                    break;
                                case "6":
                                    payBill(empId);
                                    break;
                                case "9":
                                    loop = false;
                                    break;
                                default:
                                    System.out.println("你的输入有误，请重新输入");
                                    break;
                            }
                        }
                    } else {
                        System.out.println("===============登录失败================");
                    }
                    break;
                case "2":
                    loop = false;//
                    break;
                default:
                    System.out.println("你输入有误，请重新输入.");
            }
        }
        System.out.println("你退出了满汉楼系统~");
    }

}
